package com.ifonly.mvc.methods;

import com.ifonly.common.ApiMessage;
import com.ifonly.mvc.ActionInterceptor;
import com.ifonly.mvc.ActionInvocation;
import com.ifonly.mvc.Controller;
import com.ifonly.render.RenderFactory;
import com.ifonly.utils.RequestUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author <a href="mailto:ifonlymaster@163.com">ifonly</a>
 * @version 1.0 2015-12-10 22:15
 * @since JDK 1.6
 */
public class Get extends ActionInterceptor {

    @Override
    public void doIntercept(ActionInvocation iv) {
        Controller controller = iv.getController();
        HttpServletRequest request = controller.getRequest();

        if (!RequestUtils.isGet(request)) {
            if (RequestUtils.isAjax(request)) {
                controller.renderJson(ApiMessage.failed("禁止访问"));
            } else {
                RenderFactory.getErrorRender(10001);
            }
            return;
        }
        iv.invoke();
    }

}
